package com.webvihar.access2db.adapters;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.webvihar.access2db.R;
import com.webvihar.access2db.activities.BaseActivity;
import com.webvihar.access2db.activities.DeleteDatabaseActivity;
import com.webvihar.access2db.activities.EditDatabaseActivity;
import com.webvihar.access2db.model.DbEntity;

public class DatabaseAdapter extends BaseA2DbAdapter{

	private Context mContext;
	private List<DbEntity> dbEntities;
	
	public DatabaseAdapter(Context context, List<DbEntity> dbEntities) {
		this.mContext = context;
		this.dbEntities = dbEntities;
	}

	@Override
	public int getCount() {
		return dbEntities.size();
	}

	@Override
	public Object getItem(int position) {
		return dbEntities.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		convertView = inflater.inflate(R.layout.database_list_item, null);
		TextView dbName = (TextView)convertView.findViewById(R.id.database_name_txt);
		final DbEntity entity = (DbEntity)dbEntities.get(position);
		dbName.setText(entity.dbName);
		/*ImageView editDatabaseBtn = (ImageView)convertView.findViewById(R.id.database_edit_btn);
		editDatabaseBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v){
				Intent intent = new Intent(mContext, EditDatabaseActivity.class);
				intent.putExtra(BaseActivity.KEY_DATABASE_NAME, entity.dbName);
				mContext.startActivity(intent);
			}
		});
		ImageView deleteDatabaseBtn = (ImageView)convertView.findViewById(R.id.database_delete_btn);
		deleteDatabaseBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v){
				Intent intent = new Intent(mContext, DeleteDatabaseActivity.class);
				intent.putExtra(BaseActivity.KEY_DATABASE_NAME, entity.dbName);
				mContext.startActivity(intent);
			}
		});*/
		return convertView;
	}	
}
